#include <kuai/misc/iotool.hpp>
#include <kuai/mol/space.hpp>

#ifndef _KUAI_SIM_IO_
#define _KUAI_SIM_IO_

namespace kuai {

	typedef Reader<PhaseSpace> SpaceReader;
	typedef Writer<PhaseSpace> SpaceWriter;

	class MDLMolReader 
		: public SpaceReader
	{
	public:
		virtual bool update(std::istream& stream, PhaseSpace& space) const;
	};

	class KuaiMolReader 
		: public SpaceReader
	{
	public:
		KuaiMolReader();
		explicit KuaiMolReader(const Char szCode[]);
		virtual bool update(std::istream& stream, PhaseSpace& space) const;

		static KuaiMolReader& getInstance() {
			static KuaiMolReader instance;
			return instance;
		}

	private:
		Char TAG_OF_END_OF_BLOCK;
		std::vector<Char> code;
		PropertyConnectTable* readConnectTable(std::istream& stream) const;
	};

	class MolReaderManager
		: public ReaderManager<PhaseSpace>
	{
	private:
		MolReaderManager();

	public:
		static MolReaderManager& getInstance();
	};

	
	class MDLMolWriter
		: public SpaceWriter
	{
	public:
		virtual bool write(std::ostream& stream, Reference data) const;
	};

	class KuaiMolWriter
		: public SpaceWriter
	{
	public:
		explicit KuaiMolWriter();
		explicit KuaiMolWriter(const Char szCode[]);
		virtual bool write(std::ostream& stream, Reference data) const;

		static KuaiMolWriter& getInstance() {
			static KuaiMolWriter instance;
			return instance;
		}
	private:
		Index writeConnectTable(std::ostream& stream, const ConnectTable& ct) const;
		String code;
	};

	class MolWriterManager
		: public WriterManager<PhaseSpace>
	{
	private:
		MolWriterManager();

	public:
		static MolWriterManager& getInstance();
	};

	const char* getDefaultKuaiMolKey();

}

#endif
